"""
    Author:
    Date: 2019-01-12

    微信管理后台-投诉管理页面
"""

from django.shortcuts import render

from entities import complaint_mgr
from entities import user_mgr
from entities.consts import *

from .. import helpers
from .. helpers import gma_login_required


@gma_login_required
def index(request):
    """ 首页 """
    context = helpers.build_context(request)
    context['opened_complaint_count'] = complaint_mgr.get_complaint_records_count(AUTH_STATUS_WAITING)
    context['agreed_complaint_count'] = complaint_mgr.get_complaint_records_count(AUTH_STATUS_CERTIFIED)
    context['rejected_complaint_count'] = complaint_mgr.get_complaint_records_count(AUTH_STATUS_REJECTED)
    return render(request, 'gma/complaint/complaint_home.html', context)


@gma_login_required
def opened_complaint_list(request):
    """ 开放的投诉列表 """
    logs = complaint_mgr.get_complaint_records(AUTH_STATUS_WAITING)

    context = helpers.build_context(request)
    context['logs'] = logs
    context['total_count'] = len(logs)
    return render(request, 'gma/complaint/complaint_list.html', context)


@gma_login_required
def agreed_complaint_list(request):
    """ 同意的投诉列表 """
    logs = complaint_mgr.get_complaint_records(AUTH_STATUS_CERTIFIED)

    context = helpers.build_context(request)
    context['logs'] = logs
    context['total_count'] = len(logs)
    return render(request, 'gma/complaint/complaint_list.html', context)


@gma_login_required
def rejected_complaint_list(request):
    """ 拒绝的投诉列表 """
    logs = complaint_mgr.get_complaint_records(AUTH_STATUS_REJECTED)

    context = helpers.build_context(request)
    context['logs'] = logs
    context['total_count'] = len(logs)
    return render(request, 'gma/complaint/complaint_list.html', context)


@gma_login_required
def complaint_detail(request, cid):
    """ 投诉详情 """
    log = complaint_mgr.get_complaint(cid)
    context = helpers.build_context(request)
    context['log'] = log
    context['reporter'] = user_mgr.get_user_detail(log['uid'])
    return render(request, 'gma/complaint/complaint_detail.html', context)


if __name__ == '__main__':
    print('ok')
